﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

namespace DataAccessObject
{
    public static class DataBase
    {
       static string connectionString = System.Configuration.ConfigurationSettings.AppSettings["strConn"].ToString(); 
        public static void OpenConnection()
        {
            OpenSqlConnection();
        }
        private static void OpenSqlConnection()
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
            }
        }

        private static void CreateUpdateDeleteCommand(List<string> queryString)
        {
            using (SqlConnection connection = new SqlConnection(
                       connectionString))
            {
                connection.Open();
                for (int i = 0; i < queryString.Count; i++)
                {
                    SqlCommand command = new SqlCommand(queryString[i], connection);
                    command.ExecuteNonQuery();
                }
                connection.Close();
            }
        }
        public static void CreateUpdateDelete(List<string> queryString)
        {
            CreateUpdateDeleteCommand(queryString);
        }
        private static DataTable DoExcuetQuery(string queryString)
        {
            DataTable table = new DataTable();
            using (SqlConnection connection =
                new SqlConnection(connectionString))
            {
                SqlDataAdapter adapter = new SqlDataAdapter();
                adapter.SelectCommand = new SqlCommand(
                    queryString, connection);
                adapter.Fill(table);
                return table;
            }
        }
        public static DataTable ExcuteQuery(string queryString)
        {
            return DoExcuetQuery(queryString);
        }
    }
}
